<?php
/*
显示模块
*/
function showlist($type,$sort,$num){
global $DB;
switch ($type)
{
case "xhmf":
  $where	=	"where `type` LIKE '玄幻魔法' ";
  break;  
case "wxxz":
  $where	=	"where `type` LIKE '武侠修真' ";
  break;
case "dsyq":
  $where	=	"where `type` LIKE '都市言情' ";
  break;
case "kbly":
  $where	=	"where `type` LIKE '恐怖灵异' ";
  break;
case "lsjs":
  $where	=	"where `type` LIKE '历史军事' ";
  break;
case "khxs":
  $where	=	"where `type` LIKE '科幻小说' ";
  break;
case "wydm":
  $where	=	"where `type` LIKE '网游动漫' ";
  break;
case "zttl":
  $where	=	"where `type` LIKE '侦探推理' ";
  break;
default:
  $where	=	"";
}
switch ($sort)
{
case "updatetime":
  $order	=	"ORDER BY `updatetime` desc ";
  break;  
case "new":
  $order	=	"ORDER BY `bid` desc ";
  break;  
case "monthhit":
  $order	=	"ORDER BY `monthhit` desc ";
  break;  
default:
  $order	=	"ORDER BY `allhit` desc";
}
if (IsEmpty($num))	$num	=	5;
$sql	=	"select * from book_list ".$where.$order." limit 0, ".$num;
$query	=	$DB->query($sql);
$i	=	0;
while ($result = $DB->fetch_array($query)) {
		$list[$i]["bid"] =	$result["bid"];
		$list[$i]["bname"] =	$result["bname"];
		$list[$i]["updatetime"] =	$result["updatetime"];
		$list[$i]["lastname"] =	$result["lastname"];
		$list[$i]["hottext"] =	$result["hottext"];
		$list[$i]["author"] =	$result["author"];
		$list[$i]["allhit"] =	$result["allhit"];
		$i++;
}
return $list;
}

function take_list($sort,$type,$start,$limit){
global $DB;
//echo $sort.$type.$start.$limit;
switch ($sort)
{
case "updatetime":
  $order	=	"ORDER BY `updatetime` desc ";
  break;  
case "new":
  $order	=	"ORDER BY `bid` desc ";
  break;  
case "monthhit":
  $order	=	"ORDER BY `monthhit` desc ";
  break;  
default:
  $order	=	"ORDER BY `allhit` desc";
}

switch ($type)
{
case "xhmf":
  $where	=	"where `type` LIKE '玄幻魔法' ";
  break;  
case "wxxz":
  $where	=	"where `type` LIKE '武侠修真' ";
  break;
case "dsyq":
  $where	=	"where `type` LIKE '都市言情' ";
  break;
case "kbly":
  $where	=	"where `type` LIKE '恐怖灵异' ";
  break;
case "lsjs":
  $where	=	"where `type` LIKE '历史军事' ";
  break;
case "khxs":
  $where	=	"where `type` LIKE '科幻小说' ";
  break;
case "wydm":
  $where	=	"where `type` LIKE '网游动漫' ";
  break;
case "zttl":
  $where	=	"where `type` LIKE '侦探推理' ";
  break;
default:
  $where	=	"";
}
$sql	=	"select * from book_list ".$where.$order." limit ".$start."," .$limit;
$query	=	$DB->query($sql);
$i	=	0;
while ($result = $DB->fetch_array($query)) {
		$list[$i]["bid"] =	$result["bid"];
		$list[$i]["bname"] =	$result["bname"];
		$list[$i]["updatetime"] =	$result["updatetime"];
		$list[$i]["lastname"] =	$result["lastname"];
		$list[$i]["hottext"] =	$result["hottext"];
		$list[$i]["author"] =	$result["author"];
		$list[$i]["allhit"] =	$result["allhit"];
		$i++;
}
return $list;
}

function indexsingle($bid){
global $DB;
//echo $sort.$type.$start.$limit;
$sql	=	"select * from book_list where `bid`=$bid";
$query	=	$DB->query($sql);
$result = $DB->fetch_array($query);
		$list["bid"] =	$result["bid"];
		$list["bname"] =	$result["bname"];
		$list["updatetime"] =	$result["updatetime"];
		$list["lastname"] =	$result["lastname"];
		$list["hottext"] =	$result["hottext"];
		$list["author"] =	$result["author"];
		$list["allhit"] =	$result["allhit"];
return $list;
}

function showindexsingle($bid){
$show	=	indexsingle($bid);
$bname	=	$show[bname];
$bid	=	$show[bid];
$bbid	=	floor($bid/1000);
$hottext	=	$show[hottext];
$hottext	=	str_replace("&nbsp;","",$hottext);
$hottext	=	sysSubStr($hottext,200,true);
$author	=	$show[author];
$tpl1	=	readtpl("./tpl/indexlist.html");
$tpl1	=	str_replace("<$-bname-$>",$bname,$tpl1);
$tpl1	=	str_replace("<$-bid-$>",$bid,$tpl1);
$tpl1	=	str_replace("<$-pic-$>","<img src='http://101img.info/".$bbid."/".$bid.".jpg' />",$tpl1);
$tpl1	=	str_replace("<$-hottext-$>",$hottext,$tpl1);
$tpl1	=	str_replace("<$-author-$>",$author,$tpl1);
return $tpl1;
}

function sysSubStr($String,$Length,$Append = false)
{
    if (strlen($String) <= $Length )
    {
        return $String;
    }
    else
    {
        $I = 0;
        while ($I < $Length)
        {
            $StringTMP = substr($String,$I,1);
            if ( ord($StringTMP) >=224 )
            {
                $StringTMP = substr($String,$I,3);
                $I = $I + 3;
            }
            elseif( ord($StringTMP) >=192 )
            {
                $StringTMP = substr($String,$I,2);
                $I = $I + 2;
            }
            else
            {
                $I = $I + 1;
            }
            $StringLast[] = $StringTMP;
        }
        $StringLast = implode("",$StringLast);
        if($Append)
        {
            $StringLast .= "...";
        }
        return $StringLast;
    }
} 
?>
